home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / unix / mkmkf.perl < prev    next >
Text File  |  1992-09-28  |  1KB  |  73 lines

  1. print "OBJS= ";
  2. for ($i = $#ARGV; $i >= 0; $i--)
  3. {
  4.     ($objs[$i] = $ARGV[$i]) =~ s/\.\w*$/\.o/;
  5. }
  6. &colprint(6, " ", @objs);
  7. print "\n\n";
  8.  
  9. if (-f "lmkfile.base")
  10. {
  11.     open(BASE, "lmkfile.base");
  12.     print while (<BASE>);
  13.     close(BASE);
  14. }
  15.  
  16. foreach $file (@ARGV)
  17. {
  18.     $dest = $file;
  19.     $dest =~ s/\.\w*$/\.o/;
  20.     if ($file =~ /\.c$/)
  21.     {
  22.     printf("%s: %s", $dest, $file);
  23.     $colto = length($dest) + length($file) + 2;
  24.     # Search for included files
  25.     %seen = ();
  26.     &included($file, 0);
  27.     &colprint($colto, " ", keys(%seen));
  28.     print "\n";
  29.     }
  30.     else
  31.     {
  32.     printf("%s: %s\n\n", $dest, $file);
  33.     }
  34. }
  35.  
  36. sub colprint
  37. {
  38.     local($colto, $sep, @names) = @_;
  39.     $col = $colto;
  40.     $sl = length($sep);
  41.     foreach $name (@names)
  42.     {
  43.     $nl = length($name);
  44.     if ($col + $nl + $sl > 78)
  45.     {
  46.         print " \\\n", " " x $colto;
  47.         $col = $colto;
  48.     }
  49.     print $sep, $name;
  50.     $col += $sl + $nl;
  51.     }
  52. }
  53.  
  54. sub included
  55. {
  56.     local($file, $input) = @_;
  57.     $input++;
  58.     if (!open($input, $file))
  59.     {
  60.     print STDERR "Can't open $file: $!\n";
  61.     return;
  62.     }
  63.     while (<$input>)
  64.     {
  65.     if (/^#\s*include\s*"([^"]*)"/ && !$seen{$1} && -e $1)
  66.         {
  67.         $seen{$1} = 1;
  68.         &included($1, $input);
  69.     }
  70.     }
  71.     close($input);
  72. }
  73.